﻿using System;

namespace AdAggregator.Util
{
    public static class ParseUtils
    {
        public static int? ToNullableInt(this string str)
        {
            int intValue;
            return int.TryParse(str, out intValue) ? intValue : (int?)null;
        }

        public static long? ToNullableLong(this string str)
        {
            long longValue;
            return long.TryParse(str, out longValue) ? longValue : (long?)null;
        }

        public static decimal? ToNullableDecimal(this string str)
        {
            decimal decValue;
            return decimal.TryParse(str, out decValue) ? decValue : (decimal?)null;
        }

        public static DateTime? ToNullableDateTime(this string str)
        {
            DateTime dateValue;
            return DateTime.TryParse(str, out dateValue) ? dateValue : (DateTime?)null;
        }
    }
}